from hytest import *
from lib.webui import *
from selenium.webdriver.common.by import By
import time

force_tags = ['登陆功能','冒烟测试']

def suite_setup():
    wd = open_browser()
    GSTORE['wd'] = wd
    


def suite_teardown():
    wd = GSTORE['wd']
    wd.quit()
    
class UI000x:
    ddt_cases = [
        {
            'name':'登陆UI0001',
            'para':[None,'88888888','请输入用户名']
        },{
            'name':'登陆UI0002',
            'para':['byhy',None,'请输入密码']
        },{
            'name':'登陆UI0003',
            'para':['byh','88888888','登录失败 : 用户名或者密码错误']
        },{
            'name':'登陆UI0004',
            'para':['byhy','888888','登录失败 : 用户名或者密码错误']
        },{
            'name':'登陆UI0005',
            'para':['byhy','8888888888','登录失败 : 用户名或者密码错误']
        }
    ]
    def setup(self):
        pass

    def teardown(self):
        pass

    def teststeps(self):
        username,password,expect_info = self.para
        STEP(1,'输入用户名、密码')
        wd = GSTORE['wd']
        username_input = wd.find_element(By.CSS_SELECTOR,'#username')
        password_input = wd.find_element(By.CSS_SELECTOR,'#password')
        username_input.clear()
        password_input.clear()
        if username:
            username_input.send_keys(username)
        if password:
            password_input.send_keys(password)
        
        wd.find_element(By.CSS_SELECTOR,'button').click()
        time.sleep(0.5)
        info = wd.switch_to.alert.text
        INFO(f'返回的数据是:{info}')
        CHECK_POINT('检查提示是否正确',info == expect_info)
            
        wd.switch_to.alert.accept()
        